//
//  StrongElecViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-11-19.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//
#import "ProjectCJViewController.h"
#import "StrongElecViewController.h"
@interface StrongElecViewController ()
{    
    NSMutableArray *textFieldArrs;
    NSMutableArray *childLBs;
    NSMutableArray *sendControls;
    NSMutableArray *remarkTFs;
    NSMutableArray *isNormals;
    NSMutableArray *checkIds;
    
    NSString *resultStr;
    NSString *mystr1;
    NSString *mystr2;
    NSString *mystr3;
    NSInteger controlarrcount;

    UIImage *roundSelect;
    UIImage *roundUnselect;
}
@end

@implementation StrongElecViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    NSArray *queryDataArr = [NSArray array];
    if ([Appinfomation shareIstance].strongXunJianCount == 0)
    {
        self.title = @"强电巡检（一）";
        queryDataArr = @[
  @{@"id": @"1",@"floorname":@"37F",@"rfid":@"<#string#>"},
  @{@"id": @"2",@"floorname":@"35F",@"rfid":@"<#string#>"},
  @{@"id": @"3",@"floorname":@"33F",@"rfid":@"<#string#>"},
  @{@"id": @"4",@"floorname":@"31F",@"rfid":@"<#string#>"},
  @{@"id": @"5",@"floorname":@"29F",@"rfid":@"<#string#>"},
  @{@"id": @"6",@"floorname":@"27F",@"rfid":@"<#string#>"},
  @{@"id": @"7",@"floorname":@"25F",@"rfid":@"<#string#>"},
  @{@"id": @"8",@"floorname":@"23F",@"rfid":@"<#string#>"},
  @{@"id": @"9",@"floorname":@"21F",@"rfid":@"<#string#>"},
  @{@"id": @"10",@"floorname":@"19F",@"rfid":@"<#string#>"},
  @{@"id": @"11",@"floorname":@"17F",@"rfid":@"<#string#>"},
  @{@"id": @"12",@"floorname":@"15F",@"rfid":@"<#string#>"},
  @{@"id": @"13",@"floorname":@"13F",@"rfid":@"<#string#>"},
  @{@"id": @"14",@"floorname":@"11F",@"rfid":@"<#string#>"},
  @{@"id": @"15",@"floorname":@"9F",@"rfid":@"<#string#>"},
  @{@"id": @"16",@"floorname":@"8FA",@"rfid":@"<#string#>"},
  @{@"id": @"17",@"floorname":@"7FA",@"rfid":@"<#string#>"},
  @{@"id": @"18",@"floorname":@"6FA",@"rfid":@"<#string#>"},
  @{@"id": @"19",@"floorname":@"5FA",@"rfid":@"<#string#>"},
  @{@"id": @"20",@"floorname":@"4FA",@"rfid":@"<#string#>"},
  @{@"id": @"21",@"floorname":@"3FA",@"rfid":@"<#string#>"},
  @{@"id": @"22",@"floorname":@"2FA",@"rfid":@"<#string#>"},
  @{@"id": @"23",@"floorname":@"1FA",@"rfid":@"<#string#>"},
  @{@"id": @"24",@"floorname":@"B1FA",@"rfid":@"<#string#>"},
  @{@"id": @"25",@"floorname":@"B2FA",@"rfid":@"<#string#>"},
  @{@"id": @"26",@"floorname":@"B3FA",@"rfid":@"<#string#>"}];
        self.sendUrl=[NSString stringWithFormat:addProject];
    }
    else if ([Appinfomation shareIstance].strongXunJianCount == 1)
    {
        self.title = @"强电巡检（二）";
        queryDataArr = @[
  @{@"id": @"1",@"floorname":@"38F",@"rfid":@"<#string#>"},
  @{@"id": @"2",@"floorname":@"36F",@"rfid":@"<#string#>"},
  @{@"id": @"3",@"floorname":@"34F",@"rfid":@"<#string#>"},
  @{@"id": @"4",@"floorname":@"32F",@"rfid":@"<#string#>"},
  @{@"id": @"5",@"floorname":@"30F",@"rfid":@"<#string#>"},
  @{@"id": @"6",@"floorname":@"28F",@"rfid":@"<#string#>"},
  @{@"id": @"7",@"floorname":@"26F",@"rfid":@"<#string#>"},
  @{@"id": @"8",@"floorname":@"24F",@"rfid":@"<#string#>"},
  @{@"id": @"9",@"floorname":@"22F",@"rfid":@"<#string#>"},
  @{@"id": @"10",@"floorname":@"20F",@"rfid":@"<#string#>"},
  @{@"id": @"11",@"floorname":@"18F",@"rfid":@"<#string#>"},
  @{@"id": @"12",@"floorname":@"16F",@"rfid":@"<#string#>"},
  @{@"id": @"13",@"floorname":@"14F",@"rfid":@"<#string#>"},
  @{@"id": @"14",@"floorname":@"12F",@"rfid":@"<#string#>"},
  @{@"id": @"15",@"floorname":@"10F",@"rfid":@"<#string#>"},
  @{@"id": @"16",@"floorname":@"8F",@"rfid":@"<#string#>"},
  @{@"id": @"17",@"floorname":@"7F",@"rfid":@"<#string#>"},
  @{@"id": @"18",@"floorname":@"6F",@"rfid":@"<#string#>"},
  @{@"id": @"19",@"floorname":@"5F",@"rfid":@"<#string#>"},
  @{@"id": @"20",@"floorname":@"4F",@"rfid":@"<#string#>"},
  @{@"id": @"21",@"floorname":@"3F",@"rfid":@"<#string#>"},
  @{@"id": @"22",@"floorname":@"2F",@"rfid":@"<#string#>"},
  @{@"id": @"23",@"floorname":@"1F",@"rfid":@"<#string#>"},
  @{@"id": @"24",@"floorname":@"B1F",@"rfid":@"<#string#>"},
  @{@"id": @"25",@"floorname":@"B2F",@"rfid":@"<#string#>"},
  @{@"id": @"26",@"floorname":@"B3F",@"rfid":@"<#string#>"}];
        self.sendUrl = [NSString stringWithFormat:addQiangdian2];
    }
    [super viewDidLoad];
    self.floorNames = [NSMutableArray array];
    self.floorIds = [NSMutableArray array];
    for (NSDictionary *dic in queryDataArr)
    {
        [self.floorNames addObject:[dic valueForKey:@"floorname"]];
        [self.floorIds addObject:[dic valueForKey:@"id"]];
        [self.sendFloorDatas addObject:@""];
        [self.xunJianCellInfos addObject:@{@"hidden":@"1",@"floorId":[dic valueForKey:@"id"] }];
    }
    [self initData];
    [self showUIWithArray:self.allShowDataArr andFloorId:@"1"];
    NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.myTableView selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionMiddle];

}
- (void)initData
{
    roundSelect = [UIImage imageNamed:@"选中"];
    roundUnselect = [UIImage imageNamed:@"未选中"];
    mystr1 = [NSString string];
    mystr2 = [NSString string];
    mystr3 = [NSString string];
    NSDictionary *oneDic = [NSDictionary dictionaryWithObjectsAndKeys:@"环境：",@"checkName",@"1",@"type",@"1",@"checkId", nil];
    NSDictionary *twoDic = [NSDictionary dictionaryWithObjectsAndKeys:@"ATS：",@"checkName",@"2",@"type",@"2",@"checkId", nil];
    NSDictionary *threeDic = [NSDictionary dictionaryWithObjectsAndKeys:@"MR柜：",@"checkName",@"2",@"type",@"3",@"checkId", nil];
    NSDictionary *fourDic = [NSDictionary dictionaryWithObjectsAndKeys:@"M柜：",@"checkName",@"2",@"type",@"4",@"checkId", nil];
    NSDictionary *fiveDic = [NSDictionary dictionaryWithObjectsAndKeys:@"N柜：",@"checkName",@"2",@"type",@"5",@"checkId", nil];
    NSDictionary *sixDic = [NSDictionary dictionaryWithObjectsAndKeys:@"母排插接箱：",@"checkName",@"3",@"type",@"6",@"checkId", nil];
    NSDictionary *sevenDic = [NSDictionary dictionaryWithObjectsAndKeys:@"PZ箱：",@"checkName",@"3",@"type",@"7",@"checkId", nil];
    self.allShowDataArr = @[oneDic,twoDic,threeDic,fourDic,fiveDic,sixDic,sevenDic];
}


- (void)showUIWithArray:(NSArray *)array andFloorId:(NSString *)floorId
{
    [UIView animateWithDuration:.5 animations:^{
        self.backScrollV.contentSize = CGSizeZero;
    }];
    controlarrcount = 0;
    UIImage *textImage = [UIImage imageNamed:@"输入框底"];
    [self clearAll];
    remarkTFs = [NSMutableArray array];
    sendControls = [NSMutableArray array];
    childLBs = [NSMutableArray array];
    textFieldArrs = [NSMutableArray array];
    isNormals = [NSMutableArray array];
    NSArray *showArr = [NSArray array];
    self.floorIdQuanju = floorId;
    id receiveFloorObj = [self.sendFloorDatas objectAtIndex:[self.floorIds indexOfObjectss:self.floorIdQuanju]];
    if (![receiveFloorObj isKindOfClass:[NSString class]])
    {
        self.sendCheckDatas = [receiveFloorObj objectForKey:@"checkData"];
    }
    else
    {
        self.sendCheckDatas = [NSMutableArray array];
        checkIds = [NSMutableArray array];
        for (int i = 0; i < array.count; i ++)
        {
            NSDictionary *sendDic = @{@"checkId": [NSString stringWithFormat:@"%d",i+1],@"result":@""};
            [self.sendCheckDatas addObject:sendDic];
            [checkIds addObject:[NSString stringWithFormat:@"%d",i+1]];
        }
    }
    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
    if ([Appinfomation shareIstance].strongXunJianCount == 0)
    {
        if ([floorId integerValue] >= 1 && [floorId integerValue] <= 15)
        {
            [indexSet addIndex:1];
            [indexSet addIndex:2];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:0];
        }
        else if ([floorId integerValue] == 16)
        {
            [indexSet addIndex:0];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:3];
        }
        else if([floorId integerValue] >= 17 && [floorId integerValue] <= 22 )
        {
            [indexSet addIndex:0];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:3];
        }
        else if ([floorId integerValue] == 23)
        {
            [indexSet addIndex:1];
            [indexSet addIndex:2];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:0];
            [indexSet addIndex:6];
        }
        else if ([floorId integerValue] == 24)
        {
            [indexSet addIndex:1];
            [indexSet addIndex:4];
            [indexSet addIndex:6];
            [indexSet addIndex:0];
        }
        else if ([floorId integerValue] == 25 || [floorId integerValue] == 26 )
        {
            [indexSet addIndex:0];
            [indexSet addIndex:4];
            [indexSet addIndex:6];
        }
    }
    else if ([Appinfomation shareIstance].strongXunJianCount == 1)
    {
        if ([floorId integerValue] >= 0 && [floorId integerValue] <= 23)
        {
            [indexSet addIndex:1];
            [indexSet addIndex:2];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:0];
        }
        else if ([floorId integerValue] == 24)
        {
            [indexSet addIndex:0];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
        }
        else if ([floorId integerValue] == 25)
        {
            [indexSet addIndex:0];
            [indexSet addIndex:6];
        }
        else
        {
            [indexSet addIndex:0];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:6];
        }
    }
    showArr = [array objectsAtIndexes:indexSet];
    for (int i = 0; i < showArr.count; i++)
    {
        NSDictionary *dic = [showArr objectAtIndex:i];
        NSString *checkName = [dic valueForKey:@"checkName"];
        NSString *type = [dic valueForKey:@"type"];
        NSString *checkId = [dic valueForKey:@"checkId"];
        NSDictionary *checkDic = [NSDictionary dictionary];
        UILabel *titleLb = [UILabel new];
        titleLb.text = checkName;
        titleLb.font = [UIFont systemFontOfSize:25];
        CGSize mySz = [titleLb.text sizeWithFont:titleLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        titleLb.frame = CGRectMake(10, [[self.controlWillClears lastObject]frame].origin.y + [[self.controlWillClears lastObject]frame].size.height + interval111, mySz.width, mySz.height);
        [self.backScrollV addSubview:titleLb];
        [self.controlWillClears addObject:titleLb];
        
        UILabel *label = [UILabel new];
        NSMutableArray *textArr = [NSMutableArray array];
        switch ([type integerValue])
        {
            case 1:
            {
                label.text = @"温度（˚C）";
                label.font = [UIFont systemFontOfSize:25];
                mySz = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                label.frame = CGRectMake(52, titleLb.frame.origin.y + titleLb.frame.size.height + 10, mySz.width, mySz.height);
                [self.backScrollV addSubview:label];
                [childLBs addObject:label];
                [self.controlWillClears addObject:label];
                
                UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.origin.x + label.frame.size.width, label.frame.origin.y, 100, mySz.height)];
                textF.background = textImage;
                textF.tag = 250 ;
                textF.keyboardType = UIKeyboardTypeNumberPad;
                textF.text = [[self.sendCheckDatas objectAtIndex:i]valueForKey:@"result"];
                if (![textF.text isEqualToString:@""]&&([textF.text integerValue] > 35||[textF.text integerValue] < 10))
                {
                    textF.textColor = [UIColor redColor];
                }
                else
                {
                    textF.textColor = [UIColor blackColor];
                }

                textF.delegate = self;
                [self.backScrollV addSubview:textF];
                [textArr addObject:textF];
                [textFieldArrs addObject:textArr];
                [self.controlWillClears addObject:textF];
                checkDic = @{@"checkId": checkId,@"controls":textArr};
                controlarrcount ++;
            }
                break;
            case 2:
            {
                label.text = @"电流(A)";
                label.font = [UIFont systemFontOfSize:25];
                mySz = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                label.frame = CGRectMake(titleLb.frame.origin.x + 10, titleLb.frame.origin.y + titleLb.frame.size.height + 10, mySz.width, mySz.height);
                [self.backScrollV addSubview:label];
                [childLBs addObject:label];
                [self.controlWillClears addObject:label];
                
                NSArray *childNames = @[@"A相：",@"B相：",@"C相："];
                NSString *receiveString = [[self.sendCheckDatas objectAtIndex:i]valueForKey:@"result"];
                NSArray *childString = [NSArray array];
                if ([receiveString isEqualToString:@""])
                {
                    childString = @[@"",@"",@""];
                }
                else
                {
                    childString = [receiveString componentsSeparatedByString:@","];
                }
                for (int j = 0; j<childNames.count; j++)
                {
                    UILabel *childLab = [UILabel new];
                    childLab.text = [childNames objectAtIndex:j];
                    childLab.font = [UIFont systemFontOfSize:25];
                    mySz = [childLab.text sizeWithFont:childLab.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                    childLab.frame = CGRectMake((self.backScrollV.frame.size.width - label.frame.size.width - label.frame.origin.x)/3*j + label.frame.size.width + label.frame.origin.x + interval111, label.frame.origin.y, mySz.width, mySz.height);
                    [self.backScrollV addSubview:childLab];
                    [self.controlWillClears addObject:childLab];
                    
                    UITextField *childTF = [[UITextField alloc]initWithFrame:CGRectMake(childLab.frame.origin.x + childLab.frame.size.width, childLab.frame.origin.y, 70, mySz.height)];
                    childTF.background = textImage;
                    childTF.text = [childString objectAtIndex:j];
                    if (![childTF.text isEqualToString:@""] && [childTF.text integerValue]<60 )
                    {
                        childTF.textColor = [UIColor redColor];
                    }
                    else
                    {
                        childTF.textColor = [UIColor blackColor];
                    }
                    childTF.delegate = self;
                    childTF.keyboardType = UIKeyboardTypeNumberPad;
                    [self.backScrollV addSubview:childTF];
                    [textArr addObject:childTF];
                    [self.controlWillClears addObject:childTF];
                }
                [textFieldArrs addObject:textArr];
                controlarrcount ++;
                checkDic = @{@"checkId": checkId,@"controls":textArr};
            }
                break;
            case 3:
            {
                NSMutableArray *btnArr = [NSMutableArray array];
                NSString *receiveString = [[self.sendCheckDatas objectAtIndex:i]valueForKey:@"result"];
                for (int j =0; j<self.abnormals.count; j++)
                {
                    UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                    [selectBtn setImage:roundUnselect forState:UIControlStateNormal];
                    if ([[NSString stringWithFormat:@"%d",j] isEqualToString: receiveString] && j == 0)
                    {
                        [selectBtn setImage:roundSelect forState:UIControlStateNormal];
                    }
                    else if(([[receiveString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isEqualToString:@"无异常"] && j == 0) ||([[receiveString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isEqualToString:@"异常"] && j == 1))
                    {
                        [selectBtn setImage:roundSelect forState:UIControlStateNormal];
                    }
                    [selectBtn addTarget:self action:@selector(selectOptions:) forControlEvents:UIControlEventTouchUpInside];
                    selectBtn.frame = CGRectMake(62 + (self.backScrollV.frame.size.width - 62)/2*j, titleLb.frame.origin.y + (titleLb.frame.size.height + 10), roundSelect.size.width, roundSelect.size.height);
                    [self.backScrollV addSubview:selectBtn];
                    [btnArr addObject:selectBtn];
                    [self.controlWillClears addObject:selectBtn];
                    
                    UILabel *abnormLb = [UILabel new];
                    NSString *abnormStr = [self.abnormals objectAtIndex:j];
                    abnormLb.font = [UIFont systemFontOfSize:25];
                    abnormLb.text = abnormStr;
                    CGSize mySize = [abnormLb.text sizeWithFont:abnormLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                    abnormLb.frame = CGRectMake(selectBtn.frame.origin.x + selectBtn.frame.size.width, selectBtn.frame.origin.y, mySize.width, mySize.height);
                    [self.backScrollV addSubview:abnormLb];
                    [childLBs addObject:abnormLb];
                    [self.controlWillClears addObject:abnormLb];
                }
                [self.selectBtnArr addObject:btnArr];
                UILabel *remarkLb = [UILabel new];
                remarkLb.text = @"备注：";
                remarkLb.font = [UIFont systemFontOfSize:25];
                CGSize mySiz = [remarkLb.text sizeWithFont:remarkLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                remarkLb.frame = CGRectMake(50, [[childLBs lastObject]frame].origin.y + ([[childLBs lastObject]frame].size.height + interval111), mySiz.width, mySiz.height);
                [self.backScrollV addSubview:remarkLb];
                [self.controlWillClears addObject:remarkLb];
                
                UITextField *remarkTf = [[UITextField alloc]initWithFrame:CGRectMake(remarkLb.frame.origin.x + remarkLb.frame.size.width, remarkLb.frame.origin.y, 300, mySiz.height)];
                remarkTf.background = [UIImage imageNamed:@"输入框底"];
                remarkTf.delegate = self;
                if (![[receiveString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isEqualToString:@"无异常"] && ![[receiveString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isEqualToString:@"异常"])
                {
                    remarkTf.text = [receiveString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                }
                [self.backScrollV addSubview:remarkTf];
                [remarkTFs addObject:remarkTf];
                self.backScrollV.contentSize = CGSizeMake(self.backScrollV.frame.size.width, remarkTf.frame.size.height + remarkTf.frame.origin.y + interval111);
                [self.controlWillClears addObject:remarkTf];
                [textFieldArrs  addObject:@[remarkTf]];
                [isNormals addObject:@""];
                checkDic = @{@"checkId": checkId,@"controls":btnArr};
            }
                break;
                
            default:
                break;
        }
        [sendControls addObject:checkDic];
    }
    if (![receiveFloorObj isKindOfClass:[NSString class]])
    {
        [self addCommentKuang:[receiveFloorObj objectForKey:@"floorRemark"]];
    }
    else
    {
    
        [self addCommentKuang:@""];
    }
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.myTableView) {
        return self.floorNames.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView cellForRowAtIndexPath:indexPath];
    if (tableView == self.myTableView) {
        self.mycell.textLabel.text = [self.floorNames objectAtIndex:indexPath.row];
        return self.mycell;
    }
    return nil;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self hiddenAll];
    if (tableView == self.myTableView)
    {
        [self showUIWithArray:self.allShowDataArr andFloorId:[self.floorIds objectAtIndex:indexPath.row]];
    }
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([remarkTFs containsObject:textField])
    {
        for (int k = 0; k < remarkTFs.count; k ++)
        {
            id tf = [remarkTFs objectAtIndex:k];
            BOOL isNormal = [[isNormals objectAtIndex:k]integerValue];
            if (isNormal == YES && tf == textField)
            {
                return YES;
            }
        }
        return NO;
    }
    else
    {
        return YES;
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    for (int i = 0; i < textFieldArrs.count; i++)
    {
        NSDictionary *controlDic = [sendControls objectAtIndex:i];
        NSString *checkId = [controlDic valueForKey:@"checkId"];
        NSMutableArray *controls = [textFieldArrs objectAtIndex:i];
        for (int j = 0; j < controls.count; j++)
        {
            id tf = [controls objectAtIndex:j];
            if (textField == tf)
            {
                if (controls.count == 1 && textField.tag == 250)
                {
                    if ([textField.text integerValue] > 35||[textField.text integerValue] < 10)
                    {
                        textField.textColor = [UIColor redColor];
                    }
                    else
                    {
                        textField.textColor = [UIColor blackColor];
                    }
                    resultStr = [textField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                }
                else if (controls.count == 1)
                {
                    resultStr = [textField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                }
                else if (controls.count == 3)
                {
                    if ([textField.text integerValue]<60 )
                    {
                        textField.textColor = [UIColor redColor];
                    }
                    else
                    {
                        textField.textColor = [UIColor blackColor];
                    }
                    switch (j)
                    {
                        case 0:
                        {
                            mystr1 = textField.text;
                        }
                            break;
                        case 1:
                        {
                            mystr2 = textField.text;
                        }
                            break;
                        case 2:
                        {
                            mystr3 = textField.text;
                        }
                            break;
                            
                        default:
                            break;
                    }
                    resultStr = [NSString stringWithFormat:@"%@,%@,%@",mystr1,mystr2,mystr3];
                }
                NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:checkId,@"checkId",resultStr,@"result",nil];
                int index = [checkIds indexOfObjectss:checkId];
                [self.sendCheckDatas replaceObjectAtIndex:index withObject:dic1];
                NSLog(@"%@",self.sendCheckDatas);
            }
        }
    }
}

#pragma mark - button action
- (void)selectOptions:(id)sender//工程部
{
    UIButton *btn = (UIButton*)sender;
    for (int i = 0;i<sendControls.count;i++)
    {
        NSDictionary *btnDic = [sendControls objectAtIndex:i];
        NSArray *btnArr = [btnDic valueForKey:@"controls"];
        NSString *checkId = [btnDic valueForKey:@"checkId"];
        
        if ([btnArr containsObject:btn])
        {
            for (int j = 0;j<btnArr.count;j++)
            {
                UIButton *seleBtn = [btnArr objectAtIndex:j];
                [seleBtn setImage:roundUnselect forState:UIControlStateNormal];
                if (btn == [btnArr objectAtIndex:j])
                {
                    [seleBtn setImage:roundSelect forState:UIControlStateNormal];
                    [isNormals replaceObjectAtIndex:i - controlarrcount withObject:[NSString stringWithFormat:@"%d",j]];
                    NSString *isNormal = @"";
                    UITextField *tf =[remarkTFs objectAtIndex:i - controlarrcount];
                    if (j == 0)
                    {
                        [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
                        tf.text = @"";
                        isNormal = @"无异常";
                    }
                    else if (j == 1)
                    {
                        [tf becomeFirstResponder];
                        isNormal = @"异常";
                    }
                    resultStr = [isNormal stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:checkId,@"checkId",resultStr,@"result",nil];
                    int index = 0;
                    index = [checkIds indexOfObject:checkId];
                    [self.sendCheckDatas replaceObjectAtIndex:index withObject:dic1];
                }
            }
        }
    }
    NSLog(@"%@",self.sendCheckDatas);
}
#pragma mark - end
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
